import {observable, action} from 'mobx';
import { WeaTools } from 'ecCom';
import { WeaForm } from 'comsMobx';
import { ListStoreCharts } from './listStoreCharts'
import * as API_LIST from '../../apis/chart/fnaCompactExpense'

/**
 * 合同费用分析的Store
 */
export class FnaCompactExpenseStore extends ListStoreCharts{

	//高级搜索条件值
	@observable SearchParams = {

    };

    //图表显示
    charFlag = false;

    //柱状图和饼图所有数据
    data = {};

    //最大值
    maxAmount = "0";
    //柱状图X轴值
    xAxisData = [];
    //柱状图数据
    barDatas = [];

    //饼图图例
    legendData = [];
    //饼图数据
    pieDatas = [];

	constructor(){
		super();
		this.title = "合同费用分析";
        this.pageType = "FnaCompactExpense";
	}

    //初始化数据
	initDatas = () => {
		this.doSearch();//初始化数据
	}

	//初始化高级搜索
	initInfo = () => {
        API_LIST.fnaCompactExpenseInfo().then(data => {
        	const {conditions} = data;
        	this.condition = conditions;
        	this.form.initFormFields(conditions);
        	this.setShowSearchAd(true);
        });
    }

    //搜索
    doSearch = (params = {}) => {
        const searchParamsAd = this.form.getFormParams();
        const newParams = { ...this.SearchParams, ...searchParamsAd, ...params };    
        
        this.loading = true;
        API_LIST.fnaCompactExpenseChart(newParams).then(data =>{
            this.permisflag = data.flag;
            if(this.permisflag != "failed"){
                this.data = data;
                this.maxAmount = data.maxAmount;
                this.xAxisData = data.xAxisData;
                this.barDatas = data.barDatas;
                this.legendData = data.legendData;
                this.pieDatas = data.pieDatas;
                this.charFlag = true;
            } else {
                this.charFlag = false;
            }
            this.loading = false; 
        }); 
    }
}